package gps.monitor.gpsbootstrap;

import gps.monitor.common.core.base.AbstractBootstrap;
import gps.monitor.gpsbootstrap.gpstraceanalyse.TraceAnalyserBootstrap;
import gps.monitor.gpsbootstrap.jt808Server.Jt808ServerBootstrap;
import gps.monitor.gpsbootstrap.jt809Server.Jt809ServerBootstrap;
import gps.monitor.gpsbootstrap.tool.LocalBeanTool;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;


public class GpsBootstrapApplication {

 /*   private NettyJellyMouse ioc;*/

    public static void main(String[] args) {


        new GpsBootstrapApplication().start(args);

    }

    private void start(String[] args) {
        if (args.length == 0) return;

        ConfigurableApplicationContext context = null;

        switch (args[0]) {

            case "jt809": {
                context = SpringApplication.run(Jt809ServerBootstrap.class, args);
            }
            break;

            case "jt808": {
                context = SpringApplication.run(Jt808ServerBootstrap.class, args);
            }
            break;
            case "trace": {
                context = SpringApplication.run(TraceAnalyserBootstrap.class, args);
            }
            break;
        }

        if (context == null) return;
        LocalBeanTool.init(context);

        AbstractBootstrap bootstrap = context.getBean(AbstractBootstrap.class);
        bootstrap.loadCustomConfig();

        if (bootstrap.startService()) {
            System.out.println("server started!!");
        } else {
            System.exit(-1);
        }

        enableWebApi();
    }

    private void enableWebApi() {
        try {
          /*  ioc = new NettyJellyMouse(null);
            ioc.start();*/
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
